package com.fang.unittest;

import java.io.*;
import java.util.Scanner;

public class TestDriver {
    public static void main(String[] args) throws IOException {
        test02();
    }
    private static void test01() throws IOException {
        File file = doFile();
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file.getName()));
        int a;
        while((a = bis.read()) != -1){
            bos.write(a);
        }
        bis.close();
        bos.close();
    }
    public static File doFile(){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入文件路径：");

        while(true){
            String line = sc.nextLine();
            File file = new File(line);

            if(!file.exists()){
              System.out.println("输入的文件不存在，格式出现错误");
          }else if(file.isDirectory()){
              System.out.println("输入的是文件夹，请输入文件路径");
          }else{
              return file;
          }
        }
    }
    public static void test02() throws IOException {
        Scanner sc = new Scanner(System.in);
        FileOutputStream fos = new FileOutputStream("text5.txt");
        System.out.println("请输入数据：");

        while(true){
            String line = sc.nextLine();
            if("quit".equals(line)){
                break;
            }
            fos.write(line.getBytes());
           fos.write("\r\n".getBytes());
        }

        fos.close();
    }
}
